package com.example.spotitube.Controller;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.spotitube.R;
import com.example.spotitube.Model.Track;


public class ListAdapter extends ArrayAdapter<Track>{
	
	private ArrayList<Track>	tracks;
	private Context				context;
	
	
	public ListAdapter( Context context, int textViewResourceId, ArrayList<Track> tracks ) {
		super( context, textViewResourceId, tracks );
		this.context = context;
		this.tracks = tracks;
	}
	
	
	@Override
	public View getView( int position, View convertView, ViewGroup parent ) {
		LayoutInflater inflater = ( LayoutInflater ) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
		View listItem = inflater.inflate( R.layout.list_item, parent, false );
		TextView trackName = ( TextView ) listItem.findViewById( R.id.name );
		
		Track track = tracks.get( position );
		trackName.setText( track.getTrackName() );
		
		return listItem;
	}
	
	
	public ArrayList<Track> getTracks() {
		return tracks;
	}
}
